package DB;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 *
 * @author dlesc
 */
public class Highscore {

    private Connection con;
    private Statement stat;

    /**
     * @return the con
     */
    public Connection getCon() {
        return con;
    }

    /**
     * @param con the con to set
     */
    public void setCon(Connection con) {
        this.con = con;
    }

    /**
     * @return the stat
     */
    public Statement getStat() {
        return stat;
    }

    /**
     * @param stat the stat to set
     */
    public void setStat(Statement stat) {
        this.stat = stat;
    }

    public Highscore() {
        try {
            Class.forName("org.sqlite.JDBC");
            setCon(DriverManager.getConnection("jdbc:sqlite:" + System.getProperty("user.dir") + System.getProperty("file.separator") + "game.db"));
            setStat(getCon().createStatement());
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    public void newEntry(String nick, int punkte) {
        try {
            getStat().executeUpdate("create table people (name, occupation);");
        } catch (SQLException ex) {
            ex.printStackTrace();
        }
    }

    public ResultSet getHighscore() {
        try {
            return getStat().executeQuery("SELECT nick, punkte FROM Highscore ORDER BY punkte DESC LIMIT 15");
        } catch (SQLException ex) {
            ex.printStackTrace();
            return null;
        }
    }
}
